<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>一个小案例</title>
  <script src="/js/vue.js"></script>
  <style>
    .active{
        color: red;
    }
  </style>
</head>
<body>
  <div id="app">
    <!-- 把后台数组数据在页面无序列表展示，鼠标点击哪个，哪个就变红 -->
    <ul>
        <li :class="{active:chooseIndex === key}" v-for="(book,key) in books" :key="book" @click="btnClick(key)">{{key}}+{{book}}</li>
    </ul>

  </div>    
<br>
  <script>
    let app = new Vue({
      el:"#app",
      data:{ 
        msg:'hello world',
        books:["西游记","三国演义","红楼梦","水浒传"],
        chooseIndex:''
      },
      methods: {
        btnClick(key){
            this.chooseIndex = key
        }
      },
    })
  </script>
</body>
</html>